<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

return [
    'id' => 'app-platform',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'platform\controllers',
    'components' => [
        'request' => [
            'enableCsrfValidation' => false,
            'enableCookieValidation' => false,
            'enableCsrfCookie' => false,
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ]
        ],
        'user' => [
            'identityClass' => 'platform\models\User',
            'enableAutoLogin' => false,
            'enableSession' => false,
        ],
        'session' => [
            // this is the name of the session cookie used for login on the platform
            'name' => 'advanced-platform',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            // 'suffix' => '.html',
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'passport',
                    'extraPatterns' => [
                        'POST,OPTIONS' => 'login',
                        'GET,POST,OPTIONS' => 'logout',
                    ]
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'account'
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'user',
                    'extraPatterns' => [
                        'GET,OPTIONS <id:\d>/assigned-roles' => 'assigned-roles',
                        'POST,OPTIONS <id:\d>/assign' => 'assign',
                        'POST,OPTIONS <id:\d>/revoke' => 'revoke',
                    ]
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'upload'
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'config',
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'authority/role',
                    'extraPatterns' => [
                        'GET,OPTIONS ' => 'index',
                        'POST,OPTIONS' => 'create',
                        'PUT,OPTIONS <name>' => 'update',
                        'DELETE,OPTIONS <name>' => 'delete',
                        'GET,OPTIONS <name>/assigned-permissions' => 'assigned-permissions',
                        'POST,OPTIONS <name>/assign' => 'assign',
                        'POST,OPTIONS <name>/remove' => 'remove',
                    ]
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'authority/route',
                    'extraPatterns' => [
                        'GET,OPTIONS app-routes' => 'app-routes',
                        'PUT,OPTIONS' => 'update',
                    ]
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'test'
                ],
            ],
        ],
    ],
    'params' => $params,
    'defaultRoute' => 'test/index',
];
